/****************************************************************************/
/* ObjectType																*/
/****************************************************************************/

/* Constructor */
ObjectType = class( function( self, id, name, className )

	/* Debug output */
	DEBUG:Msg( "Instanciating ObjectType with " .. tostring( name ), "ObjectType.ctor" )

	/* Members */
	self.ID				= id
	self.Name			= name
	self.ClassName		= className
end)

/****************************************************************************/
/* ObjectReferenceType														*/
/****************************************************************************/

/* Constructor */
ObjRefType = class( function( self, id, name )

	/* Debug output */
	DEBUG:Msg( "Instanciating ObjRefType with " .. tostring( name ), "ObjRefType.ctor" )

	/* Members */
	self.ID				= id
	self.Name			= name
end)

/****************************************************************************/
/* LevelInfo																*/
/****************************************************************************/

/* Constructor */
LevelInfo = class( function( self, num, requiredXp )

	/* Debug output */
	DEBUG:Msg( "Instanciating LevelInfo with " .. tostring( num ), "LevelInfo.ctor" )

	/* Members */
	self.Num			= num
	self.RequiredXp		= requiredXp
end)

/****************************************************************************/
/* ObjectInfo																*/
/****************************************************************************/

/* Constructor */
ObjectInfo = class( function( self, id, name, health, weight, tp, reference, refTp, price )

	/* Debug output */
	DEBUG:Msg( "Instanciating ObjectInfo with " .. tostring( name ), "ObjectInfo.ctor" )

	/* Validate type */
	if not IsValidInstance( tp, ObjectType ) then
		DEBUG:ErrMsg( "Invalid object type: " .. tostring( tp ), "ObjectInfo.ctor" )
		return false
	end
	
	/* Validate reference type */
	if not IsValidInstance( refTp, ObjRefType ) then
		DEBUG:ErrMsg( "Invalid object reference type: " .. tostring( refTp ), "ObjectInfo.ctor" )
		return false
	end

	/* Members */
	self.ID				= id
	self.Name			= name
	self.Health			= health
	self.Weight			= weight
	self.Type			= tp
	self.Reference		= reference
	self.ReferenceType	= refTp
	self.Price			= price
end)

/****************************************************************************/
/* Loadout																	*/
/****************************************************************************/

/* Constructor */
Loadout = class( function( self, id, name, primary, secondary, inv1, inv2, backpack1, backpack2 )

	/* Debug output */
	DEBUG:Msg( "Instanciating Loadout with " .. tostring( name ) .. " (ID = " .. tostring( id ) .. ")", "Loadout.ctor" )

	/* Validate primary */
	if not IsValidInstance( primary, ObjectInfo ) or not IsValidInstance( primary.Type, ObjectType ) or primary.Type.ClassName != "primary" then
		if primary then
			DEBUG:Msg( "Invalid primary weapon: " .. tostring( primary.Type.Name ) .. ", " .. tostring( primary.Type.ClassName ), "Loadout.ctor" )
		else
			DEBUG:Msg( "Invalid primary weapon: " .. tostring( primary ), "Loadout.ctor" )
		end
	end
	
	/* Validate secondary */
	if not IsValidInstance( secondary, ObjectInfo ) or not IsValidInstance( secondary.Type, ObjectType ) or secondary.Type.ClassName != "secondary" then
		if secondary then
			DEBUG:Msg( "Invalid secondary weapon: " .. tostring( secondary.Type.Name ) .. ", " .. tostring( secondary.Type.ClassName ), "Loadout.ctor" )
		else
			DEBUG:Msg( "Invalid secondary weapon: " .. tostring( secondary ), "Loadout.ctor" )
		end
	end
	
	/* Validate inventory 1 */
	if not IsValidInstance( inv1, ObjectInfo ) or not IsValidInstance( inv1.Type, ObjectType ) or inv1.Type.ClassName != "inventory" then
		if inv1 then
			DEBUG:Msg( "Invalid first inventory item: " .. tostring( inv1.Type.Name ) .. ", " .. tostring( inv1.Type.ClassName ), "Loadout.ctor" )
		else
			DEBUG:Msg( "Invalid first inventory item: " .. tostring( inv1 ), "Loadout.ctor" )
		end
	end
	
	/* Validate inventory 2 */
	if not IsValidInstance( inv2, ObjectInfo ) or not IsValidInstance( inv2.Type, ObjectType ) or inv2.Type.ClassName != "inventory" then
		if inv2 then
			DEBUG:Msg( "Invalid second inventory item: " .. tostring( inv2.Type.Name ) .. ", " .. tostring( inv2.Type.ClassName ), "Loadout.ctor" )
		else
			DEBUG:Msg( "Invalid second inventory item: " .. tostring( inv2 ), "Loadout.ctor" )
		end
	end
	
	/* Validate backpack 1 */
	if not IsValidInstance( backpack1, ObjectInfo ) or not IsValidInstance( backpack1.Type, ObjectType ) then
		if backpack1 then
			DEBUG:Msg( "Invalid first backpack object: " .. tostring( backpack1.Type.Name ) .. ", " .. tostring( backpack1.Type.ClassName ), "Loadout.ctor" )
		else
			DEBUG:Msg( "Invalid first backpack object: " .. tostring( backpack1 ), "Loadout.ctor" )
		end
	end
	
	/* Validate backpack 2 */
	if not IsValidInstance( backpack2, ObjectInfo ) or not IsValidInstance( backpack2.Type, ObjectType ) then
		if backpack2 then
			DEBUG:Msg( "Invalid second backpack object: " .. tostring( backpack2.Type.Name ) .. ", " .. tostring( backpack2.Type.ClassName ), "Loadout.ctor" )
		else
			DEBUG:Msg( "Invalid second backpack object: " .. tostring( backpack2 ), "Loadout.ctor" )
		end
	end

	/* Members */
	self.ID				= id
	self.Name			= name
	self.Primary		= primary
	self.Secondary		= secondary
	self.Inventory1		= inv1
	self.Inventory2		= inv2
	self.Backpack1		= backpack1
	self.Backpack2		= backpack2
end)

/****************************************************************************/
/* UpgradeInfo																*/
/****************************************************************************/

/* Constructor */
UpgradeInfo = class( function( self, id, name, level, addHealth, addWeight, price, object, previous, next )

	/* Debug output */
	DEBUG:Msg( "Instanciating UpgradeInfo with " .. tostring( name ), "UpgradeInfo.ctor" )

	/* Validate level */
	if not IsValidInstance( level, LevelInfo ) then
		DEBUG:ErrMsg( "Invalid level info: " .. tostring( level ), "UpgradeInfo.ctor" )
		return false
	end
	
	/* Validate object */
	if not IsValidInstance( object, ObjectInfo ) then
		DEBUG:ErrMsg( "Invalid object info: " .. tostring( object ), "UpgradeInfo.ctor" )
		return false
	end

	/* Members */
	self.ID				= id
	self.Name			= name
	self.Level			= level
	self.AddHealth		= addHealth
	self.AddWeight		= addWeight
	self.Price			= price
	self.Object			= object
	self.Previous		= previous
	self.Next			= next
end)

/****************************************************************************/
/* PlayerStats																*/
/****************************************************************************/

/* Constructor */
PlayerStats = class( function( self, ply, tm, kills, deaths, rescued, escaped, friendsKilled, enemiesRescued, experience, level )

	/* Debug output */
	DEBUG:Msg( "Instanciating PlayerStats with " .. tostring( ply ) .. ", " .. tostring( tm ), "PlayerStats.ctor" )

	/* Validate player */
	if not player.IsValid( ply ) then
		DEBUG:ErrMsg( "Invalid player: " .. tostring( ply ), "PlayerStats.ctor" )
		return false
	end
	
	/* Validate team */
	if not team.Valid( tm ) then
		DEBUG:ErrMsg( "Invalid team: " .. tostring( tm ), "PlayerStats.ctor" )
		return false
	end
	
	/* Validate level */
	if not IsValidInstance( level, LevelInfo ) then
		DEBUG:ErrMsg( "Invalid level info: " .. tostring( level ), "PlayerStats.ctor" )
		return false
	end

	/* Members */
	self.Player			= ply
	self.Team			= team.GetInfo( tm )
	self.Kills			= kills
	self.Deaths			= deaths
	self.Rescued		= rescued
	self.Escaped		= escaped
	self.FriendsKilled	= friendsKilled
	self.EnemiesRescued	= enemiesRescued
	self.Experience		= experience
	self.Level			= level
end)

/****************************************************************************/
/* PlayerUpgrade															*/
/****************************************************************************/

/* Constructor */
PlayerUpgrade = class( function( self, ply, upgrade, dateAcquired )

	/* Debug output */
	DEBUG:Msg( "Instanciating PlayerUpgrade with " .. tostring( ply ) .. ", " .. tostring( upgrade ), "PlayerUpgrade.ctor" )

	/* Validate player */
	if not player.IsValid( ply ) then
		DEBUG:ErrMsg( "Invalid player: " .. tostring( ply ), "PlayerUpgrade.ctor" )
		return false
	end
	
	/* Validate upgrade */
	if not IsValidInstance( level, LevelInfo ) then
		DEBUG:ErrMsg( "Invalid upgrade: " .. tostring( upgrade ), "PlayerUpgrade.ctor" )
		return false
	end

	/* Members */
	self.Player			= ply
	self.Upgrade		= upgrade
	self.DateAcquired	= dateAcquired
end)

/****************************************************************************/
/* UserInfo																	*/
/****************************************************************************/

/* Constructor */
UserInfo = class( function( self, ply, login, password, adminLevel )

	/* Debug output */
	DEBUG:Msg( "Instanciating UserInfo with " .. tostring( ply ), "UserInfo.ctor" )

	/* Validate player */
	if not player.IsValid( ply ) then
		DEBUG:Msg( "Invalid player: " .. tostring( ply ), "UserInfo.ctor" )
	end

	/* Members */
	self.Player			= ply
	self.Login			= login
	self.Password		= password
	self.AdminLevel		= adminLevel
end)